module Piston
  module Output
    include Observable

    def add_observer(observer)
      @observer_peers = [] unless defined? @observer_peers
      @observer_peers.push observer
    end

    def write(str)
      if defined? @observer_peers
        @observer_peers.each do |o|
          o.write(str)
        end
      end
    end
    alias :print :write

    def puts(str)
      write("#{str}\n")
    end

    extend self
  end
end